package com.ceshiren.hogwarts.app.contact;

import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class ContactPage extends BasePage{


    public ContactPage(AndroidDriver androidDriver) {
        super(androidDriver);
    }

    public ContactPage addMember(String name,String sex,String mobile){
        //点击右上角进入添加成员
        click(By.id("com.tencent.wework:id/i6i"));
        //点击添加成员
        click(By.id("com.tencent.wework:id/e30"));
        //点击手动输入
        click(By.xpath("//*[@text='手动输入添加']"));
        //输入姓名
        sendKeys(By.id("com.tencent.wework:id/b4t"),name);
        //点击箭头
        click(By.id("com.tencent.wework:id/b55"));
        //点击性别
        click(By.xpath("//*[@text='"+sex+"']"));
        //输入电话号码
        sendKeys(By.id("com.tencent.wework:id/fow"),mobile);
        //保存
        click(By.id("com.tencent.wework:id/i6k"));
        return this;

    }

    public ContactPage searchContent(String name) throws Exception{
        Thread.sleep(10000);
       /* new WebDriverWait(androidDriver,20).until(ExpectedConditions.presenceOfElementLocated(By.id("i63"))).click();
        click(By.id("com.tencent.wework:id/i6d"));*/
        //点击放大镜
        System.out.println ("fang da jing ==========");
        click(By.id("com.tencent.wework:id/i6n"));
        click(By.xpath("//*[@text='搜索']"));
        sendKeys(By.id("com.tencent.wework:id/gpg"),name);
        return this;
    }

    public String getCurrentMemberName(){
        StringBuilder name = new StringBuilder();
        androidDriver.findElements(By.xpath("//android.widget.ListView//android.widget.TextView")).forEach(element->{
            name.append(((WebElement)element).getText());
        });
        System.out.println("====="+name);
        return name.toString();
    }

}
